package model;

public class ParsingData
{
    private final String symbol;
    private int priority;
    private int numArgs;
    private boolean isFunction;
    private boolean isLeftAssoc;

    private final Class<?> tokenClass;
    private final Class<?> expressionClass;

    public ParsingData(String symbol, int priority, int numArgs, 
                               boolean isFunction, boolean isLeftAssoc,
                               String tokenClass, String expressionClass) throws ClassNotFoundException
    {
        this.symbol = symbol;
        this.priority = priority;
        this.numArgs = numArgs;
        this.isFunction = isFunction;
        this.isLeftAssoc = isLeftAssoc;
        this.tokenClass = Class.forName(tokenClass);
        this.expressionClass = Class.forName(expressionClass);
    }
    
    public String getSymbol() 
    {
        return symbol;
    }
    
    public boolean matchesSymbol(String symbol)
    {
        return symbol.matches(this.symbol);
    }
    
    public int getNumArgs()
    {
        return numArgs;
    }

    public int getPriority()
    {
        return priority;
    }
    
    public boolean isLeftAssociative()
    {
        return isLeftAssoc;
    }
    
    public boolean isFunction()
    {
        return isFunction;
    }
    
    /*
     * returns true if in expression
     * "VALUE this VALUE other VALUE"
     * should be parsed as
     * "(VALUE this VALUE) other VALUE"
     * rather than
     * "VALUE this (VALUE other VALUE)"
     */
    public boolean takesPriorityOver(ParsingData other)
    {
        if (isFunction)
            return false;
        else if (other.isLeftAssociative()) 
            return priority >= other.getPriority();
        else 
            return priority > other.getPriority();
            
    }

    public int getNumArguments() {
		return numArgs;
	}

	public Class<?> getTokenClass(){
		return tokenClass;
	}

	public Class<?> getExpressionClass(){
		return expressionClass;
	}
}
